package homework;

import java.util.Stack;

//作业标题(2724)
//用栈实现队列
//
//作业内容
//用栈实现队列
//https://leetcode.cn/problems/implement-queue-using-stacks/description/
public class h2724 {
    class MyQueue {
        private Stack<Integer> st1;
        private Stack<Integer> st2;
        public MyQueue() {
            st1 = new Stack<>();
            st2 = new Stack<>();
        }

        public void push(int x) {
            st1.push(x);
        }

        public int pop() {
            if(empty()) return -1;
            if(st2.empty())
            {
                while(!st1.empty())
                {
                    st2.push(st1.pop());
                }
            }
            return st2.pop();
        }

        public int peek() {
            if(empty()) return -1;
            if(st2.empty())
            {
                while(!st1.empty())
                {
                    st2.push(st1.pop());
                }
            }
            return st2.peek();
        }

        public boolean empty() {
            return st1.empty() && st2.empty();
        }
    }

}
